home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / gnome-wm < prev    next >
Encoding:
Text File  |  2009-04-08  |  4.0 KB  |  168 lines

  1. #!/bin/sh
  2.  
  3. # The user can specify his prefered WM by setting the WINDOW_MANAGER
  4. # environment variable or setting the
  5. # /desktop/gnome/applications/window_manager/default gconf key.
  6. #
  7. # If this is not set, we search a list of known windowmanagers and use
  8. # the first one that is found in the users's PATH
  9. #
  10. # NOTE: DON'T USE THIS.  Please have your window manager install
  11. # a desktop file and change the gconf key
  12. # /desktop/gnome/session/required_components/windowmanager
  13.  
  14. # sm-client-id value
  15. SMID=
  16. # default-wm value
  17. DEFWM=
  18.  
  19. #read in the arguments
  20. GET=
  21. for n in "$@" ; do
  22.   case "$GET" in
  23.     smid)
  24.       SMID=$n
  25.       GET=
  26.       ;;
  27.     defwm)
  28.       DEFWM=$n
  29.       GET=
  30.       ;;
  31.     *)
  32.       case "$n" in
  33.         --sm-client-id)
  34.           GET=smid
  35.           ;;
  36.         --default-wm)
  37.           GET=defwm
  38.           ;;
  39.       esac
  40.       ;;
  41.   esac
  42. done
  43.  
  44. # Get previously set window manager in gconf
  45. if [ ! "$DEFWM" ]; then
  46.   DEFWM=`gconftool-2 -g /desktop/gnome/applications/window_manager/default 2>/dev/null`
  47. fi
  48.  
  49. # special case handling for dapper upgrades (this runs only once after the upgrade)
  50. if [ -z "$DEFWM" ] && [ -f /var/lib/gnome-session/dapper-upgrade ]; then
  51.     gconftool-2 -s /desktop/gnome/applications/window_manager/default /usr/bin/metacity --type string
  52.     DEFWM=/usr/bin/metacity
  53. fi
  54.  
  55. # If not exist, set to compiz (if available) 
  56. if [ ! -x "$DEFWM" ]; then
  57.     if [ -x "/usr/bin/compiz" ]; then
  58.     gconftool-2 -s /desktop/gnome/applications/window_manager/default /usr/bin/compiz --type string
  59.     DEFWM=/usr/bin/compiz
  60.     elif [ -x "/usr/bin/metacity" ]; then
  61.     gconftool-2 -s /desktop/gnome/applications/window_manager/default /usr/bin/metacity --type string
  62.     DEFWM=/usr/bin/metacity
  63.     else
  64.     unset DEFWM
  65.     fi
  66. fi
  67.  
  68. # WINDOW_MANAGER overrides all
  69. if [ -z "$WINDOW_MANAGER" ] ; then
  70.     WINDOW_MANAGER=`gconftool-2 --get /desktop/gnome/session/required_components/windowmanager 2> /dev/null`
  71. fi
  72.  
  73. # Avoid looping if the session configuration tells us to use gnome-wm or if
  74. # the user forces gnome-wm via WINDOW_MANAGER
  75. if [ "x$WINDOW_MANAGER" = "xgnome-wm" ]; then
  76.   WINDOW_MANAGER=""
  77. fi
  78.  
  79. if [ -z "$WINDOW_MANAGER" ] ; then
  80.   # Create a list of window manager we can handle, trying to only use the
  81.   # compositing ones when it makes sense
  82.  
  83.   xdpyinfo 2> /dev/null | grep -q "^ *Composite$" 2> /dev/null
  84.   IS_X_COMPOSITED=$?
  85.  
  86.   KNOWN_WM="sawfish sawmill enlightenment icewm wmaker fvwm2 qvwm fvwm twm kwm"
  87.   if [ $IS_X_COMPOSITED -eq 0 ] ; then
  88.     KNOWN_WM="compiz beryl $KNOWN_WM"
  89.   fi
  90.   # metacity is still the default wm in GNOME
  91.   KNOWN_WM="metacity $KNOWN_WM"
  92.  
  93.   OLDIFS=$IFS
  94.   if [ -z "$DEFWM" -o "x$DEFWM" = "xgnome-wm" ]; then
  95.     for wm in $KNOWN_WM ; do
  96.       IFS=":"
  97.       for dir in $PATH ; do
  98.     if [ -x "$dir/$wm" ] ; then
  99.       WINDOW_MANAGER="$dir/$wm"
  100.           break 2
  101.     fi
  102.       done
  103.       IFS=$OLDIFS
  104.     done
  105.   else
  106.     WINDOW_MANAGER=$DEFWM
  107.   fi
  108.   IFS=$OLDIFS
  109. fi
  110.  
  111. # If no window manager can be found, we default to xterm
  112.  
  113. if [ -z "$WINDOW_MANAGER" ] ; then
  114.   echo "WARNING: No window manager can be found."
  115.   WINDOW_MANAGER=`readlink /etc/alternatives/x-terminal-emulator 2>/dev/null`
  116. fi
  117.  
  118. # Now create options OPT1, OPT2 and OPT3 based on the windowmanager used
  119. OPT1=
  120. OPT2=
  121. OPT3=
  122. OPT4=
  123. if [ ! -z "$SMID" ] ; then
  124.   case `basename $WINDOW_MANAGER` in
  125.     sawfish|sawmill|metacity)
  126.       OPT1=--sm-client-id=$SMID
  127.       ;;
  128.     openbox|enlightenment|e16)
  129.       OPT1=--sm-client-id
  130.       OPT2=$SMID
  131.       ;;
  132.     twm)
  133.       OPT1=-clientId
  134.       OPT2=$SMID
  135.       ;;
  136.     lwm)
  137.       OPT1=-s
  138.       OPT2=$SMID
  139.       ;;
  140.     fvwm)
  141.       OPT1=-i
  142.       OPT2=$SMID
  143.       ;;
  144.     compiz)
  145.       OPT1=--sm-client-id
  146.       OPT2=$SMID
  147.       ;;
  148.     beryl)
  149.       OPT1=--sm-client-id
  150.       OPT2=$SMID
  151.       ;;
  152.     #FIXME: add all other windowmanagers here with their proper options
  153.   esac
  154. fi
  155.  
  156. case `basename $WINDOW_MANAGER` in
  157.   beryl)
  158.     emerald &
  159.     ;;
  160. esac
  161.  
  162. # Store the selected WM with gconf
  163. gconftool-2 -t string -s /desktop/gnome/applications/window_manager/current "$WINDOW_MANAGER"
  164.  
  165. exec $WINDOW_MANAGER $OPT1 $OPT2 $OPT3 $OPT4
  166.  
  167. echo "ERROR: No window manager could run!"
  168.